<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>0-1背包</title>
    <style>
        body {
            font-family: 'Arial', sans-serif;
            margin: 0;
            padding: 0;
            background-color: #f4f7fc;
        }
        .container {
            max-width: 800px;
            margin: 30px auto;
            background-color: #fff;
            padding: 20px;
            border-radius: 10px;
            box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
        }
        h1 {
            text-align: center;
            color: #333;
            font-size: 24px;
        }
        form {
            margin-bottom: 20px;
            text-align: center;
        }
        button {
            background-color: #4CAF50;
            color: white;
            padding: 10px 20px;
            font-size: 16px;
            border: none;
            border-radius: 5px;
            cursor: pointer;
        }
        button:hover {
            background-color: #45a049;
        }
        table {
            width: 100%;
            max-width: 100%;
            border-collapse: collapse;
            margin: 20px auto;
        }
        th, td {
            border: 1px solid #ddd;
            padding: 12px;
            text-align: center;
        }
        th {
            background-color: #f4f4f4;
            color: #555;
        }
        td {
            background-color: #fafafa;
        }
        tr:nth-child(even) td {
            background-color: #f9f9f9;
        }
        .dp-table {
            overflow-x: auto;
        }
        .btn-container {
            text-align: center;
            margin-top: 20px;
        }
        .btn-container a {
            text-decoration: none;
            color: white;
        }
    </style>
</head>
<body>
    <div class="container">
        <h1>动态规划求解0-1背包</h1>

        <form method="post">
            {% csrf_token %}
            <button type="submit">点击计算</button>
        </form>

        <h2>计算结果</h2>

        <div class="dp-table">
            <h3>DP表格</h3>
            <table>
                <thead>
                    <tr>
                        <th>行\列</th>
                        {% for col in table.0 %}
                            <th>{{ forloop.counter0 }}</th>
                        {% endfor %}
                    </tr>
                </thead>
                <tbody>
                    {% for row in table %}
                    <tr>
                        <th>{{ forloop.counter0 }}</th>
                        {% for cell in row %}
                        <td>{{ cell }}</td>
                        {% endfor %}
                    </tr>
                    {% endfor %}
                </tbody>
            </table>
        </div>

        <h3>最优解</h3>
        <p>最优价值：{{ result_value }}</p>

        <h3>选择的物品</h3>
        <table>
            <thead>
                <tr>
                    <th>编号</th>
                    <th>重量</th>
                </tr>
            </thead>
            <tbody>
                {% for items in selected_items %}
                <tr>
                    <td>{{ items.0 }}</td>
                    <td>{{ items.1 }}</td>
                </tr>
                {% endfor %}
            </tbody>
        </table>
        {{ time }}
        <div class="btn-container">
            <button><a href="{% url 'experiment3' %}">返回上一页</a></button>
        </div>
    </div>
</body>
</html>